<template>
  <view class="container">
    <!--<station-info v-if="id" :stationId="id" />-->
    <detail :baseInfo="baseInfo" :trader="trader" :formData="formData" />
    <fixed-footer>
      <u-button
          class="footer-btn"
          @click="save"
          style="width: 30%;margin-right: 15px"
      >暂存</u-button>
      <u-button
          type="primary"
          class="footer-btn"
          color="#dab386"
          @click="submit"
      >完工</u-button>
    <!--  <u-button-->
    <!--      class="footer-btn"-->
    <!--      @click="reject"-->
    <!--      style="width: 30%;margin-right: 15px"-->
    <!--  >验收驳回</u-button>-->
    <!--  <u-button-->
    <!--      type="primary"-->
    <!--      class="footer-btn"-->
    <!--      @click="pass"-->
    <!--  >验收通过</u-button>-->
    </fixed-footer>
	</view>
</template>

<script>
	import ModuleCard from "../../../../../components/business/module-card/index.vue";
  import UButton from "../../../../../uni_modules/uview-ui/components/u-button/u-button.vue";
  import UForm from "../../../../../uni_modules/uview-ui/components/u-form/u-form.vue";
  import UFormItem from "../../../../../uni_modules/uview-ui/components/u-form-item/u-form-item.vue";
  import UTextarea from "../../../../../uni_modules/uview-ui/components/u--textarea/u--textarea.vue";
  import FixedFooter from "../../../../../components/business/fixed-footer/index.vue";
  import {getCustomerEntryDetail} from "../../../../../api/customer";
  import {AZIMUTH} from "../../../../../constant";
  import {
    fixAcceptPassApi,
    fixAcceptRefuseApi, getAcceptInfoApi,
    getUsedMaterialInfoApi, installApi,
    installZcApi
  } from "../../../../../api/common/power-station";
  import detail from "./detail/index.vue";
  import {getProjectCompanyByIdApi} from "../../../../../api/common/trader";
  import {filerImageUrlParams} from "../../../../../static/utils/handleImage";

  export default {
    name: "index",
    computed: {
      AZIMUTH() {
        return AZIMUTH
      }
    },
    components: {FixedFooter, UTextarea, UFormItem, UForm, UButton, ModuleCard, detail},
		data() {
			return {
        show: true,
        baseInfo: {},
        trader: {},
        formData: {
          id: '',
          zjPlateImg: '',
          nbqPlateImg: '',
          nbqPlateTwoImg: '',
          txPlateImg: '',
          txPlateTwoImg: '',

          zjImg1: '',
          zjImg2: '',
          zjImg3: '',
          zjImg4: '',
          zjImg5: '',

          componentImg1: '',
          componentImg2: '',
          componentImg3: '',
          componentImg4: '',

          totalImgs: '',
          dcImgs: '',
          bwInnerImg: '',
          underwallCableImg: '',
          dqsbAnImgOne: '',
          dqsbAnImgTwo: '',
          cableTowardsImg: '',

          zujianJdImg: '',
          zjJdImg: '',
          jdjImg: '',
          nbqBwxJdImg: '',
          jdOtherImg: '',

          zcKlImg1: '',
          zcKlImg2: '',
          zcKlImg3: '',

          jdDzImg1: '',
          gfFzImg: '',
          nbqZbImg: '',

          snOne: '', // 组件sn
          snTwo: '',
          nbqSnOne: '', // 逆变器sn
          nbqSnTwo: '',

          // 补充字段
          jdDlImg2: '', // 电器接地电路测试2
          finishOtherImg: '', // 其他
          dqsbAnimgOne: '',
          dqsbAnimgTwo: '',
          FinishOtherImg: '',
        },
        id: '',
        rules:  {}
			}
		},
    onLoad(options) {
      this.id = options.id;
      this.init()
    },
		methods: {
      async init() {
        await this.getDetail()
        await this.getProjectCompanyById()
        await this.getInstallInfo()
      },
      // 获取详情
      async getDetail() {
        const { data } = await getCustomerEntryDetail(this.id);
        this.baseInfo = data;
      },
      // 根据ID查询代理商信息
      async getProjectCompanyById() {
        const { data } = await getProjectCompanyByIdApi(this.baseInfo?.distributorId);
        this.trader = data;
      },
      // 获取安装验收信息
      async getInstallInfo() {
        const { data } = await getAcceptInfoApi(this.id);
        // this.formData.id = this.id;
        this.formData.entryId = this.id;
        this.formData = data.report || this.formData;
        this.formData.snOne = data.snOne;
        this.formData.snTwo = data.snTwo;
        this.formData.nbqSnOne = data.nbqSnOne;
        this.formData.nbqSnTwo = data.nbqSnTwo;
      },
      async save(){
        this.formData.entryId = this.id;
        let data = JSON.parse(JSON.stringify(this.formData));
        data = filerImageUrlParams(data);
        await installZcApi(data);
        // 提示暂存成功
        uni.showToast({
          title: '暂存成功',
          icon: 'none',
          duration: 2000
        });
      },
      // 完工
      async submit(){
        this.formData.status = 0;
        this.formData.entryId = this.id;
        let data = JSON.parse(JSON.stringify(this.formData));
        data = filerImageUrlParams(data);
        await installApi(data);
        // 提示暂存成功
        uni.showToast({
          title: '暂存成功',
          icon: 'none',
          duration: 2000
        });
      },
      // // 获取详情
      // async getDetail(id) {
      //   const { data } = await getCustomerEntryDetail(id);
      //   this.formData = Object.assign({}, this.formData, data)
      // },
      // 驳回
      // async reject() {
      //   await fixAcceptRefuseApi({entryId: this.id});
      //   // 提示驳回成功
      //   uni.showToast({
      //     title: '驳回成功',
      //     icon: 'none',
      //     duration: 2000
      //   });
      // },
      // 通过
      // async pass() {
      //   await fixAcceptPassApi({entryId: this.id});
      //   // 提示通过成功
      //   uni.showToast({
      //     title: '通过成功',
      //     icon: 'none',
      //     duration: 2000
      //   });
      // },
		}
	}
</script>

<style lang="scss" scoped>
.upload-wrap{
  margin: 15px 0 0;
}
.container{
  padding-bottom: 70px;
}
.form-item-title{}
.form-item-subtitle{
  font-size: 12px;
  color: #666;
  margin-top: 0px;
  .required{
    color: #ff0000;
    margin-right: 2px;
  }
}
.border-bottom{
  border-bottom: 1px solid #e8e8e8;
}
.mb-10{
  margin-bottom: 10px;
}
.no-margin{
  margin-top: 0px !important;
}
.footer-btn{
  margin: 0 0px;
  width: 100%;
}
.base-info{
  position: relative;
  height: 80px;
  overflow: hidden;
  *{
    transition: all 1s ease-in-out;
  }
  //由下向上白色渐变透明蒙层
  &.show{
    //min-height: 473px;
    height: auto;
    .mask{
      display: none;
    }
  }
  .mask{
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 80px;
    background: linear-gradient(to top, rgba(255,255,255,1), rgba(255,255,255,0));
  }
}
.toggle{
  display: inline-block;
  margin: 20px 0;
  background: #f9a512;
  text-align: center;
  padding: 5px 15px;
   color: #fff;
  border-radius: 15px;
  position: relative;
  left: 50%;
  transform: translateX(-50%);
}
</style>
